package test;


import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.ps.dao.setting.AreaDAO;
import com.ps.dao.setting.FunctionModuleDAO;
import com.ps.dao.setting.RoleDAO;
import com.ps.entity.Result;
import com.ps.pojo.dept.Department;
import com.ps.pojo.person.Employee;
import com.ps.pojo.setting.Area;
import com.ps.pojo.setting.FunctionModule;
import com.ps.pojo.setting.Role;
import com.ps.service.dept.DepartmentService;
import com.ps.service.dept.imp.DepartmentServiceImp;
import com.ps.service.person.EmployeeService;
import com.ps.service.person.imp.EmployeeServiceImp;
import com.ps.service.setting.FunctionModuleService;
import com.ps.service.setting.UnqueNumberService;
import com.ps.service.setting.imp.FunctionModuleServiceImp;
import com.ps.service.setting.imp.UnqueNumberServiceImp;
import com.ps.util.Kit;
import com.ps.util.R;
import com.ps.view.tree.Tree;

public class Main {

	/**
	 * @param args
	 * @throws Exception 
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {
		ApplicationContext ac = new FileSystemXmlApplicationContext("src/applicationContext.xml");
		final DepartmentServiceImp service = ac.getBean(DepartmentServiceImp.class);

		//List<Department> list = service.getBaseDao().getHibernateTemplate().findByNamedQuery("query_id_dept_recursive", 1);

		System.out.println(service.findXmlTree(1));
		
		
		
/*		for (int i = 0; i < 100; i++) {
			MRun r = new MRun(service, i);
			r.run();
		} */
		
/*		FunctionModuleDAO dao = ac.getBean(FunctionModuleDAO.class);
		List<FunctionModule> list = dao.findAll();
		for (FunctionModule fm : list) {
			System.out.println(fm.getName());
			
			Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
			System.out.println(gson.toJson(fm));
			
			JsonElement je =  gson.toJsonTree(fm);
			ArrayList alist = new ArrayList(fm.getPermissions());  
			
			je.getAsJsonObject().add("permissions", gson.toJsonTree(alist));
			
			System.out.println(gson.toJson(je));
			
		}*/
		
//		System.out.println(json);
		
		
		
/*		Serializer serializer = new Persister();
		
		File result = new File("C:/Users/Administrator/Downloads/dhtmlxTree/dhtmlxTree/samples/common/tree3.xml");

		Tree tree = serializer.read(Tree.class, result);*/
		
		
		//System.out.println(R.string.getProperty("addsucces"));
		
	}
	
	static class MRun implements Runnable {
		
		UnqueNumberService service;
		int index;
        public MRun(UnqueNumberService service, int index) {
        	this.service = service;
        	this.index = index;
        }
		
		public void run() {
            try {
            	int s = RandomUtils.nextInt(100);
            	System.out.println("s = " + s);
				Thread.sleep(s);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			String value = service.increaseCodeValue("EMP_NO");
			
			
			System.out.println(value +  "-- index =  " + index);
		}
		
	}

}
